package com.yanqu.road.entity.servercenter;

import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.FieldTypeAnnotation;
import com.yanqu.road.utils.string.StringUtils;

import java.util.ArrayList;
import java.util.List;

@FieldTypeAnnotation(tableName = "t_s_system_loop_config")
public class SystemLoopConfig extends DataObject {
    @FieldTypeAnnotation(desc = "唯一id", select = true, update = true)
    private int id;
    @FieldTypeAnnotation(desc = "渠道", select = true, update = true)
    private int channelId;
    @FieldTypeAnnotation(desc = "开服天数范围")
    private String openDays;
    @FieldTypeAnnotation(desc = "系统范围")
    private String systemIds;
    @FieldTypeAnnotation(desc = "修改时间")
    private long modifyTime;

    //左闭右开
    private List<Integer> openDayList = new ArrayList<>();
    //系统轮询顺序
    private List<Integer> systemIdList = new ArrayList<>();

    public SystemLoopConfig() {
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getChannelId() {
        return channelId;
    }

    public void setChannelId(int channelId) {
        this.channelId = channelId;
    }

    public String getOpenDays() {
        return openDays;
    }

    public void setOpenDays(String openDays) {
        this.openDays = openDays;
        this.openDayList = StringUtils.stringToIntegerList(openDays, "-");
    }

    public String getSystemIds() {
        return systemIds;
    }

    public void setSystemIds(String systemIds) {
        this.systemIds = systemIds;
        this.systemIdList = StringUtils.stringToIntegerList(systemIds, ":");
    }

    public long getModifyTime() {
        return modifyTime;
    }

    public void setModifyTime(long modifyTime) {
        this.modifyTime = modifyTime;
    }

    public List<Integer> getOpenDayList() {
        return openDayList;
    }

    public List<Integer> getSystemIdList() {
        return systemIdList;
    }

    public int getStartDay() {
        return openDayList.get(0);
    }

    public int getEndDay() {
        return openDayList.get(1) - 1;
    }

    //获得systemId的下一个systemId
    public int getNextSystemId(int systemId) {
        if (systemIdList.size() == 0) {
            return 0;
        }
        if (systemId == 0) {
            return systemIdList.get(0);
        }
        int idx = systemIdList.indexOf(systemId);
        if (idx == -1) {
            return systemIdList.get(0);
        }
        idx = (idx + 1) % systemIdList.size();
        return systemIdList.get(idx);
    }
}
